package com.zzq.guli.service.edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzq.guli.service.base.model.TeacherQuery;
import com.zzq.guli.service.edu.entity.Teacher;
import com.zzq.guli.service.edu.mapper.TeacherMapper;
import com.zzq.guli.service.edu.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author ZZQ
 * @since 2024-04-12
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {


    @Autowired
    TeacherMapper teacherMapper;
    @Override
    public Page<Teacher> selectPage(Integer page, Integer limit, TeacherQuery teacherQuery) {

        Page<Teacher> teacherPage = new Page<>(page,limit);

        QueryWrapper<Teacher> teacherQueryWrapper1 = new QueryWrapper<>();

        if(teacherQuery.getJoinDateBegin() == null&&teacherQuery.getJoinDateEnd()==null&&teacherQuery.getName()==null&&teacherQuery.getLevel()==null){
            Page<Teacher> teacherPage1 = teacherMapper.selectPage(teacherPage, null);
            return teacherPage1;
        }

        if (!StringUtils.isEmpty(teacherQuery.getName())) {
            teacherQueryWrapper1.like("name", teacherQuery.getName());
        }

        if(teacherQuery.getLevel()!=null){
            teacherQueryWrapper1.eq("level", teacherQuery.getLevel());
        }

        if(!StringUtils.isEmpty(teacherQuery.getJoinDateBegin())){
            teacherQueryWrapper1.gt("joinDateBegin",teacherQuery.getJoinDateBegin());
        }

        if(!StringUtils.isEmpty(teacherQuery.getJoinDateEnd())){
            teacherQueryWrapper1.lt("joinDateEnd",teacherQuery.getJoinDateEnd());
        }

        return teacherMapper.selectPage(teacherPage, teacherQueryWrapper1);
    }
}
